package com.yimi.policyservice.repository;

import com.yimi.policyservice.entity.base.system.SysMenu;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * @author jack
 */
public interface SysMenuRepository extends JpaRepository<SysMenu,String> {
    List<SysMenu> findByParentMenuIdOrderByMenuSortAsc(String id);

    List<SysMenu> findByMenuLevel(Long i);
    
    @Query(value = "select * " +
            "from t_sys_menu " +
            "where id in ( " +
            "  select rp.menu_id " +
            "  from t_sys_role_permission rp " +
            "  where role_id in (select ru.role_id from t_sys_user_role ru where ru.user_id = ?1) " +
            "and PARENT_MENU_ID" +
            ")",nativeQuery = true)
    List<SysMenu>findUserMenu(String id);


}
